package MeHua;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class NewButton extends JButton {
    private String s;
    private int sizeX;
    private int sizeY;
    private Font font1 =new Font("宋体",Font.BOLD,30);
    public NewButton(String s ,int sizeX,int sizeY,Font font)    //传递图片引用
    {
        super(s);
        this.sizeX = sizeX;
        this.sizeY = sizeY;
        setContentAreaFilled(false);
        this.setForeground(Color.white);
        this.setFont(font);
        this.addMouseListener(new MouseAdapter() {
           public void mouseEntered(MouseEvent e) {
                setForeground(new Color(0,139,0));
           }
           public void mouseExited(MouseEvent e) {
              setForeground(Color.white);
           }
        });
    }
    protected void paintComponent(Graphics g)    //绘制按钮内容
    {
        g.setColor(new Color(163,187,219));
        g.fillRoundRect(0,0,getSize().width-1,getSize().height-1,15,15);;//绘制一个圆角矩形getSize()为获取组件的大小
        //g.drawImage(img, 0,0,50, 40, null);      //除了形状外还可以为按钮绘制一个图片来美化按钮
        super.paintComponent(g);	//使用父类函数绘制一个焦点框
    }

    protected void paintBorder(Graphics g)   //绘制按钮边框
    {
        g.drawRoundRect(0, 0, getSize().width - 1, getSize().height - 1, 15, 15);
    }

    @Override
    public void setFont(Font font) {
        super.setFont(font);
    }
}
